#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<vector<string>> data;
vector<string> data_set;
int file_count, tab_count;
void output(vector<string> data_set);

int main(int argc, char const* argv[])
{
    int case_num = 0;
    while (true) {
        string input;
        cin >> input;
        if (input.size() == 1 && input[0] == '#')
            break;
        if (input.size() == 1 && input[0] == '*') {
            case_num++;
            data.push_back(data_set);
            while (!data_set.empty())
                data_set.clear();
        } else {
            data_set.push_back(input);
        }
    }
    for (int i = 0; i < data.size(); i++) {
        cout << "DATA SET " << i + 1 << ":" << endl;
        cout << "ROOT" << endl;
        file_count = tab_count = 0;
        output(data[i]);
        cout << endl;
    }
    return 0;
}

void output(vector<string> data_set)
{
    vector<string> file_data;
    while (true) {
        if (file_count == data_set.size() || data_set[file_count][0] == ']') {
            file_count++;
            tab_count--;
            break;
        } else if (data_set[file_count][0] != 'd')
            file_data.push_back(data_set[file_count++]);
        else if (data_set[file_count][0] == 'd') {
            for (int i = 0; i < tab_count + 1; i++)
                cout << "|     ";
            cout << data_set[file_count++] << endl;
            tab_count++;
            output(data_set);
        }
    }
    sort(file_data.begin(), file_data.end());
    for (int i = 0; i < file_data.size(); i++) {
        for (int i = 0; i < tab_count + 1; i++)
            cout << "|     ";
        cout << file_data[i] << endl;
    }
}

/*
数据结构设计+递归
其中递归很要命
*/